<!DOCTYPE html>
<html>
<head>
<title>ECSHOP 管理中心 - 编辑商品 </title>
<meta name="robots" content="noindex, nofollow">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="__PUBLIC__/admin/css/general.css" rel="stylesheet" type="text/css" />
<link href="__PUBLIC__/admin/css/main.css" rel="stylesheet" type="text/css" />

<link href="__PUBLIC__/css/layui.css" rel="stylesheet" type="text/css" media="all"/>
<script type="text/javascript" src="__PUBLIC__/layui.js"></script>

</head>
<body>

<h1>
<span class="action-span"><a href="{:U('admin/goods/goodslist')}">商品列表</a></span>
<span class="action-span1"><a href="index.php?act=main">编辑商品</a></span>
<div style="clear:both"></div>
</h1>

<div class="tab-div">

    <!-- tab body -->
    <div id="tabbody-div">
    <a href="javascript:history.back(-1)" style="position: absolute;right: 21%;top: 43px;border: 1px solid;padding: 5px 6px;background: #ECECEC;">返回</a>
      <form class="layui-form" method="post">
        <!-- 最大文件限制 -->
        <!-- <input type="hidden" name="MAX_FILE_SIZE" value="2097152" /> -->
        <!-- 通用信息 -->
        <table width="60%" id="general-table" align="center" style="box-shadow: 1px 1px 15px 1px;">
          <tr>
            <td class="label">商品名称：</td>
            <td>
                <input type="text" name="goods_name"  value="{$goods_info.goods_name}" required  lay-verify="required" placeholder="请输入商品名称" style="height: 25px;margin-bottom: 5px;margin-top: 5px;"/>
            </td>
          </tr>
          <tr>
            <td class="label">商品分类：</td>
            <td>
            <div style="width: 150px;margin-bottom: 10px;">
            <select name="cat_id"  >
              <?php foreach ($cats as $v) { ?>
              <option value="{$v.cat_id}" {$v['cat_id']==$goods_info['cat_id']?"selected":''}>{$v.lev|str_repeat='&nbsp;',###}{$v.cat_name}</option>
              <?php } ?>
            </select>
            </div>
            </td>
          </tr>
          <tr>
            <td class="label">本店售价：</td>
            <td><input type="text" name="shop_price" value="{$goods_info.shop_price}" required  lay-verify="required" placeholder="请输入商品单价" style="height: 25px;margin-bottom: 10px;" /> 元</td>
          </tr>
          <tr>
            <td class="label">库存数量：</td>
            <td><input type="text" name="goods_number" value="{$goods_info.goods_number}" required  lay-verify="required" placeholder="请输入商品数量" style="height: 25px;margin-bottom: 10px;" /> 件</td>
          </tr>
          <tr>
            <td class="label">商品图片：</td>
            <td>
              <img id="LAY_demo_upload" src="__ROOT__{$goods_info.thumb_img}" style="width: 250px;height: 350px;">
              <input type="file" name="goods_img" style="height: 25px;margin-bottom: 10px;" id="goods_img" lay-title="更新图片"/>
              <span style="position: relative;left: -105px;top: 45px;color: red;display: inline-block;height: 40px;">* 上传完图片记得<br>&nbsp;&nbsp;点底部的更新按钮</span>
              <input type="hidden" name="new_goods_img" id="new_goods_img" value="">
              <input type="hidden" name="new_thumb_img" id="new_thumb_img" value="">
            </td>
          </tr>
          <tr>
            <td class="label">商品描述： </td>
            <td>
            <div style="width: 400px;"><textarea class="layui-textarea" name="goods_desc" id="LAY_demo1">{$goods_info.goods_desc}</textarea></div><br />
            <span class="notice-span" style="display:block"  id="noticeSellerNote">* 简单描述，尽量不要超过20字。</span></td>
          </tr>
        </table>
        <div class="button-div">
          <input type="hidden" name="goods_id" value="{$goods_info.goods_id}">
          <button lay-submit lay-filter="*" style="padding: 5px 15px;"> 更新 </button>
        </div>
      </form>
    </div>
</div>
<!-- end goods form -->

<script type="text/javascript">
    layui.use(['form','layedit','upload'], function(){
      $ = layui.jquery;
      var layer = layui.layer
      ,layedit = layui.layedit
      ,form = layui.form();
      //layer.msg('Hello World');

  layui.upload({
    url: "{:U('admin/goods/good_img')}"
    ,elem: '#goods_img' //指定原始元素，默认直接查找class="layui-upload-file"
    ,method: 'post' //上传接口的http类型
    ,success: function(res){
      if (res.code ==0) {
        layer.msg(res.msg,{icon:5});
      }else{
        layer.msg(res.msg,{icon:6});
        LAY_demo_upload.src = res.data.src;
        $("#new_goods_img").val(res.data.ori_url);
        $("#new_thumb_img").val(res.data.thumb_url);
      };
    }
  });

  //创建一个编辑器
  var editIndex = layedit.build('LAY_demo1', {height: 100,
                tool: ['strong','italic','underline','del']
                });

    form.on('submit(*)', function(data){
        data.field.goods_desc = layedit.getContent(editIndex);
        $.ajax({
            url: "{:U('admin/goods/goodsdit')}",//请求地址
            type: "post",//请求方式
            dataType: "json",//返回数据类型
            data: data.field,//发送的参数
            })
            .done(function(response) {
                  if(response.error==0){
                     layer.msg(response.info ,{icon:5});

                  }else{
                     layer.msg(response.info ,{icon:6});
                     location.href = response.url;
                  }
              })
            .fail(function() {
                alert("ajxs交互失败");
            })  

          return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });  
    });
</script>
</body>
</html>